﻿<!--/* 
* Copyright (c) 2009, The University of Texas at Austin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, 
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, 
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, 
* this list of conditions and the following disclaimer in the documentation and/or other materials 
* provided with the distribution.
*
* Neither the name of The University of Texas at Austin nor the names of its contributors may be 
* used to endorse or promote products derived from this software without specific prior written 
* permission.
* 
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/-->
    
<UserControl x:Class="Bio.Views.Structure.SecondaryStructureBrowser"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ViewModels="clr-namespace:Bio.Views.Structure.ViewModels"
    xmlns:Structure="clr-namespace:Bio.Views.Structure">
    <UserControl.Resources>        
        <Structure:StructureModelColorConverter x:Key="ColorConverter"></Structure:StructureModelColorConverter>
        
        <DataTemplate DataType="{x:Type ViewModels:SSSymbolViewModel}">
            <TextBlock x:Name="NTSymbol"
                       Text="{Binding Path=Symbol.Value}"
                       FontFamily="{Binding Path=Typeface.FontFamily}"
                       FontStyle="{Binding Path=Typeface.Style}"
                       FontWeight="{Binding Path=Typeface.Weight}"
                       FontSize="{Binding Path=FontSize}">
            </TextBlock>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=Visible}" Value="False">
                    <Setter Property="Visibility" TargetName="NTSymbol" Value="Collapsed"></Setter>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
        
        <DataTemplate DataType="{x:Type ViewModels:SSBasePairViewModel}">
            
        </DataTemplate>
        
        <DataTemplate DataType="{x:Type ViewModels:SSBasePairCircleConnectorViewModel}">
            <Grid Width="{Binding Path=BasePair.Width}"
                  Height="{Binding Path=BasePair.Height}">
                <Grid Width="{Binding Path=BasePair.FivePrimeNucleotide.Width}"
                      Height="{Binding Path=BasePair.FivePrimeNucleotide.Height}">
                    <Ellipse x:Name="BPConnectorCircle" 
                             Stroke="{Binding Path=Color, Converter={StaticResource ColorConverter}}"
                             StrokeThickness="{Binding Path=Thickness}"
                             Width="{Binding Path=Diameter}"
                             Height="{Binding Path=Diameter}">         
                    </Ellipse>
                </Grid>
            </Grid>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=Filled}" Value="True">
                    <Setter Property="Fill" TargetName="BPConnectorCircle" Value="{Binding Path=Color, Converter={StaticResource ColorConverter}}"></Setter>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>

        <DataTemplate DataType="{x:Type ViewModels:SSBasePairLineConnectorViewModel}">
            <Line x:Name="BPConnectorLine"
                  X1="0"
                  Y1="0"
                  X2="{Binding Path=Width}"
                  Y2="{Binding Path=Height}"
                  Stroke="{Binding Path=Color, Converter={StaticResource ColorConverter}}"
			      StrokeThickness="{Binding Path=Thickness}"
                  RenderTransformOrigin=".5,.5">
            </Line>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=Visible}" Value="False">
                    <Setter Property="Visibility" TargetName="BPConnectorLine" Value="Collapsed"></Setter>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
        
        <DataTemplate DataType="{x:Type ViewModels:SSTextLabelViewModel}">
            <TextBlock Text="{Binding Path=Text}"
                       FontFamily="{Binding Path=FontFamily}"
                       FontSize="{Binding Path=FontSize}"
                       Foreground="{Binding Path=Color}"
                       FontWeight="{Binding Path=FontWeight}"
                       FontStyle="{Binding Path=FontStyle}"></TextBlock>
        </DataTemplate>
        
        <DataTemplate DataType="{x:Type ViewModels:SSLineLabelViewModel}">
            <Line X1="0.0"
                  Y1="0.0"
                  X2="{Binding Path=X1}"
                  Y2="{Binding Path=Y1}"
                  Stroke="{Binding Path=Color}"
                  StrokeThickness="{Binding Path=Thickness}">
            </Line>
        </DataTemplate>
        
        <DataTemplate DataType="{x:Type ViewModels:SSParallelogramLabelViewModel}">
            <Polygon Points="{Binding Path=VertexPoints}"
                     Stroke="{Binding Path=Color}"
                     StrokeThickness="{Binding Path=LineWeight}">
            </Polygon>
        </DataTemplate>
        
        <DataTemplate DataType="{x:Type ViewModels:SSArcLabelViewModel}">
            <Path Stroke="{Binding Path=Color}"
                  StrokeThickness="{Binding Path=LineWeight}"
                  Data="{Binding Path=Curve}"></Path>
        </DataTemplate>
        
        <DataTemplate DataType="{x:Type ViewModels:SSArrowLabelViewModel}">
            <Polyline Points="{Binding Path=EdgePoints}"
                      Stroke="{Binding Path=Color}"
                      StrokeThickness="{Binding Path=LineWeight}">
                <Polyline.RenderTransform>
                    <RotateTransform Angle="{Binding Path=RotationAngle}"></RotateTransform>
                </Polyline.RenderTransform>
            </Polyline>
        </DataTemplate>
        
    </UserControl.Resources>
    <DockPanel>
        <StatusBar DockPanel.Dock="Top">
            <StatusBarItem>
                <StackPanel Orientation="Horizontal">
                    <TextBlock>2-D Diagram: </TextBlock>
                    <TextBlock Text="{Binding ElementName=ss, Path=SelectedItem}"></TextBlock>
                </StackPanel>
            </StatusBarItem>
            <StatusBarItem HorizontalAlignment="Right">
                <StackPanel Orientation="Horizontal">
                    <TextBlock>Zoom:</TextBlock>
                    <Slider x:Name="viewScaler"
                        Value="1"
                        Minimum=".5"
                        Maximum="10"
                        Width="100"
                        TickFrequency=".5"></Slider>
                </StackPanel>
            </StatusBarItem>
        </StatusBar>
        <ListBox x:Name="ss"
                 ItemsSource="{Binding Path=ModelElements}"
                 Style="{x:Null}">
            <ListBox.ItemContainerStyle>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="Canvas.Left" Value="{Binding Path=X}"></Setter>
                    <Setter Property="Canvas.Top" Value="{Binding Path=Y}"></Setter>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                <Border x:Name="ssItemBd"
                                        BorderThickness="1"
                                        RenderTransformOrigin=".5,.5">
                                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                    </ContentPresenter>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsSelected" Value="True">
                                        <Setter Property="BorderBrush" TargetName="ssItemBd" Value="Gold" />
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ListBox.ItemContainerStyle>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas Width="{Binding Path=MaxWidth}"
                            Height="{Binding Path=MaxHeight}">
                        <Canvas.LayoutTransform>
                            <TransformGroup>
                                <ScaleTransform ScaleX="{Binding ElementName=viewScaler, Path=Value}"
                                                ScaleY="{Binding ElementName=viewScaler, Path=Value}"
                                                CenterX="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ScrollViewer}}, Path=ContentHorizontalOffset}"
                                                CenterY="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ScrollViewer}}, Path=ContentVerticalOffset}"></ScaleTransform>
                            </TransformGroup>
                        </Canvas.LayoutTransform>
                    </Canvas>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>
    </DockPanel>
</UserControl>
